package com.xjtu.platform.user.checker;


/**
 * @创建人 mby381
 * @创建时间 2021-12-17
 * @描述
 */

import com.xjtu.platform.common.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.transform.TransformerConfigurationException;
import java.util.List;

@RestController
@RequestMapping("/checker")
public class CheckerAPI {


    @Resource
    private CheckerService checkerService;


    @RequestMapping(value = "/info",method = RequestMethod.GET)
    public Result getInfo(){
        try{
            List<ReqDto> result = checkerService.findAllRecord();
            if (result!=null){
                System.out.println("获取需求列表成功");
                return Result.success("查询成功",result);
            }else{
                return Result.fail(400,"需求列表为空！！");
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return Result.fail(400,"查询失败！");
    }

    @RequestMapping(value = "/updStage",method = RequestMethod.POST)
    public Result checkUpd(@RequestBody ReqDto dto) {
        if(dto.getStage()==1){
            return Result.success("需求已审核！");
        }
        try{
            checkerService.checkUpdReq(dto);
            return Result.success("修改成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.fail(400,"更新状态失败！");
    }

    @RequestMapping(value = "/refuReq",method = RequestMethod.POST)
    public Result refuseReq(@RequestParam String request_id){
        try {
            System.out.println(request_id);
            checkerService.refuseReq(request_id);
            return Result.success("已拒绝需求");
        }catch (Exception e){
            e.printStackTrace();
        }

        return Result.fail(400,"服务器错误！");
    }

}
